import React from "react"
import { connect } from "react-redux"
import { bindActionCreators } from 'redux';
import { Button } from 'antd';
import * as actions from "./User/actions"

class reduxThunk0101 extends React.Component {
    constructor(props) {
        super(props);
        console.log(this.props)
    }

    render() {
        return (

            <div>
                {
                    !!this.props.User.user.title ? <p> {this.props.User.user.title}</p> : <p> "暂无数据"</p>
                }
                
                {
                    this.props.User.isFetching ? <p>加载中</p> :
                        <div className="margin_v_sm ">
                            <Button onClick={() => { this.props.counterActions.get_user() }} type="primary">获取用户信息</Button>
                        </div>

                }


            </div>

        )
    }
}
//读数据的方法
const mapStateToprops = (state) => {
    console.log(!!state.User.user.title)
    return {
        User: state.User

    }
}
const setStateToprops = (dispatch) => {
    return {
        counterActions: bindActionCreators(actions, dispatch)
    }
}
//按照顺序
export default connect(mapStateToprops, setStateToprops)(reduxThunk0101) 